package com.eling.elcms.cater.model;

import com.eling.elcms.basedoc.model.CardManagement;
import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.ordermanager.model.ServicePoint;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

import javax.persistence.*;

/**
 * 顾客消费卡
 * 
 * @author zhoulin
 *
 */
@Indexed
@Table(name = "cate_consumecard")
@Entity
@CriteriaEnhancers(criteriaEnhancers = {@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class),
		@CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "servicePoint:servicePoint") })
public class ConsumeCard extends CardManagement {

	private static final long serialVersionUID = -1063723829600442329L;

	/** 所属服务点 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkServicePoint")
	@IndexedEmbedded(depth = 1)
	private ServicePoint servicePoint;

	/** 消费卡状态 */
	@Enumerated(EnumType.STRING)
	@In
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private Status status;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status {
		
		Free("空闲"),InUse("使用中");

		private String display;
		
		Status(String display) {
			this.display = display;
		}
		
		public String getDisplay() {
			return display;
		}
	}

	public ServicePoint getServicePoint() {
		return servicePoint;
	}

	public void setServicePoint(ServicePoint servicePoint) {
		this.servicePoint = servicePoint;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
	
}
